﻿Imports System
Imports System.Globalization
Imports System.Reflection

Namespace System.Workflow.Activities.Rules
    Friend Class LiftedConversionMethodInfo
        Inherits BaseMethodInfo
        ' Methods
        Public Sub New(ByVal method As MethodInfo)
            MyBase.New(method)
            MyBase.resultType = GetType(Nullable([Of] )).MakeGenericType(New Type() { method.ReturnType })
            Dim parameters As ParameterInfo() = method.GetParameters
            MyBase.expectedParameters = New ParameterInfo() { New SimpleParameterInfo(parameters(0)) }
        End Sub

        Public Overrides Function Invoke(ByVal obj As Object, ByVal invokeAttr As BindingFlags, ByVal binder As Binder, ByVal parameters As Object(), ByVal culture As CultureInfo) As Object
            If (parameters(0) Is Nothing) Then
                Return Activator.CreateInstance(MyBase.resultType)
            End If
            Dim operandValue As Object = MyBase.actualMethod.Invoke(Nothing, invokeAttr, binder, parameters, culture)
            Return Executor.AdjustType(MyBase.actualMethod.ReturnType, operandValue, MyBase.resultType)
        End Function

    End Class
End Namespace

